package screenshot

import (
	"context"
	"fmt"
	"image"
	"runtime"

	"gitee.com/csingo/screenshot/drivers"
	"gitee.com/csingo/screenshot/drivers/windows"
)

const (
	WindowsOS = "windows"
)

func GetDriver() (driver drivers.DriverInterface, err error) {
	switch runtime.GOOS {
	case WindowsOS:
		driver = &windows.Driver{}
	default:
		return nil, fmt.Errorf("driver is not support")
	}

	return
}

func Capture(display uint, rgb bool) (img *image.RGBA, err error) {
	var driver drivers.DriverInterface
	if driver, err = GetDriver(); err != nil {
		return
	}

	return driver.Capture(display, rgb)
}

func Listen(ctx context.Context, display, fps uint, rgb bool, ch chan *image.RGBA) (err error) {
	var driver drivers.DriverInterface
	if driver, err = GetDriver(); err != nil {
		return
	}

	err = driver.Listen(ctx, display, fps, rgb, ch)

	return
}

func GetScreenSize(display uint) (width, height int, err error) {
	var driver drivers.DriverInterface
	if driver, err = GetDriver(); err != nil {
		return
	}

	width, height, err = driver.GetScreenSize(display)

	return
}
